package com.demo;

import java.util.Calendar;
import java.util.Date;

public class HelloWorld {
    /**
     * Say hello to everyone
     * @param now
     * @param user
     * @return the word what to say
     */
    public String sayHello(Date now, String user) {
        int hour = getHour(now);
        return greetToUser(user) + "" + greetAboutTime(hour);
    }

    private int getHour(Date now) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    private String greetAboutTime(int hour) {
        String word;
        if(hour>=6 && hour<12) {
            word = "Good morning!";
        } else if(hour>=12 && hour<19) {
            word = "Good afternoon!";
        } else {
            word = "Good night!";
        }
        return word;
    }

    private String greetToUser(String user) {
        return "Hi, "+user+". ";
    }
}
